﻿// WebZHX.Infrastructure/Data/Configurations/UserConfiguration.cs
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Core.Entities;

namespace Infrastructure.Data.Configurations
{
    /// <summary>
    /// 用户实体配置
    /// </summary>
    public class UserConfiguration : IEntityTypeConfiguration<User>
    {
        public void Configure(EntityTypeBuilder<User> builder)
        {
            // 表名
            builder.ToTable("Users");

            // 主键
            builder.HasKey(u => u.Id);

            // 属性配置
            builder.Property(u => u.Name)
                .IsRequired()
                .HasMaxLength(100);

            builder.Property(u => u.Email)
                .IsRequired()
                .HasMaxLength(200);

            // 索引
            builder.HasIndex(u => u.Email)
                .IsUnique();

        }
    }
}